let baseUrl = "http://127.0.0.1:1234"

function InitTimeDisplay()
{
    setInterval("SetTime('tab-bar-time')",1);
}

function GetParams(key)
{
    let reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
    let r = window.location.search.substr(1).match(reg);
    if (r != null)
        return decodeURI(r[2]);
    return null;
}

function SetTime(timeClassName)
{
    const date = new Date();
    const y = date.getFullYear();
    let m = date.getMonth() + 1;
    let d = date.getDate();
    let ww = ' 星期'+'日一二三四五六'.charAt(new Date().getDay());
    let h = date.getHours();
    let minute = date.getMinutes();
    let s = date.getSeconds();
    if(m<10) m = "0"+m;
    if(d<10) d = "0"+d;
    if(h<10) h = "0"+h;
    if(minute<10) minute = "0"+minute;
    if(s<10) s = "0"+s;
    let es = document.getElementsByClassName(timeClassName);
    for(let i = 0; i < es.length; i++)
        es[i].innerHTML = y+"-"+m+"-"+d+"   "+h+":"+minute+":"+s+"  "+ww;
}

function ShowLoadingOverlay()
{
    let mask = document.getElementById("loading-overlay");
    mask.style.display = "block";
    document.documentElement.style.overflow = "hidden";
}

function CloseLoadingOverlay()
{
    let mask = document.getElementById("loading-overlay");
    mask.style.display = "none";
    document.documentElement.style.overflow = "auto";
}

function ShowAlertOverlay(result)
{
    let mask = document.getElementById("alert-overlay");
    mask.style.display = "block";
    let text = mask.getElementsByClassName("alert-window")[0].getElementsByClassName("text-box")[0].lastElementChild;
    if (typeof result === "string")
        text.innerHTML = result;
    else
        text.innerHTML = ""
    document.documentElement.style.overflow = "hidden";
}

function CloseAlertOverlay()
{
    let mask = document.getElementById("alert-overlay");
    mask.style.display = "none";
    document.documentElement.style.overflow = "auto";
}

function ShowOkOverlay()
{
    let mask = document.getElementById("ok-overlay");
    mask.style.display = "block";
    document.documentElement.style.overflow = "hidden";
}

function CloseOkOverlay()
{
    let mask = document.getElementById("ok-overlay");
    mask.style.display = "none";
    document.documentElement.style.overflow = "auto";
}
